list1=[2,0,2,0]
def zero_to_end(list):
    for i in range(len(list)-1,-1,-1):
        if list[i]==0:
            del list[i]
            list.append(0)

def merge(list):
    zero_to_end(list)
    for i in range(len(list)-1):
        if list[i]==list[i+1]:
            list[i]+=list[i+1]
            del list[i+1]
            list.append(0)

merge(list1)
print(list1)